home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tcl / dist6.3 / tests / list.test < prev    next >
Encoding:
Text File  |  1991-12-02  |  2.9 KB  |  75 lines

  1. # Commands covered:  list
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /user6/ouster/tcl/tests/RCS/list.test,v 1.12 91/12/02 11:38:16 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. # First, a bunch of individual tests
  21.  
  22. test list-1.1 {basic tests} {list a b c} {a b c}
  23. test list-1.2 {basic tests} {list {a b} c} {{a b} c}
  24. test list-1.3 {basic tests} {list \{a b c} {\{a b c}
  25. test list-1.4 {basic tests} "list a{}} b{} c}" "a\\{\\}\\} b{} c\\}"
  26. test list-1.5 {basic tests} {list a\[ b\] } "{a\[} b\\]"
  27. test list-1.6 {basic tests} {list c\  d\t } "{c } {d\t}"
  28. test list-1.7 {basic tests} {list e\n f\$ } "{e\n} {f\$}"
  29. test list-1.8 {basic tests} {list g\; h\\} {{g;} h\\}
  30. test list-1.9 {basic tests} "list a\\\[} b\\\]} " "a\\\[\\\} b\\\]\\\}"
  31. test list-1.10 {basic tests} "list c\\\} d\\t} " "c\\} d\\t\\}"
  32. test list-1.11 {basic tests} "list e\\n} f\\$} " "e\\n\\} f\\$\\}"
  33. test list-1.12 {basic tests} "list g\\;} h\\\\} " "g\\;\\} {h\\}}"
  34. test list-1.13 {basic tests} {list a {{}} b} {a {{}} b}
  35. test list-1.14 {basic tests} {list a b xy\\} "a b xy\\\\"
  36. test list-1.15 {basic tests} "list a b\} e\\" "a b\\} e\\\\"
  37. test list-1.16 {basic tests} "list a b\}\\\$ e\\\$\\" "a b\\}\\\$ e\\\$\\\\"
  38. test list-1.17 {basic tests} {list a\f \{\f} "{a\f} \\\{\\f"
  39. test list-1.18 {basic tests} {list a\r \{\r} "{a\r} \\\{\\r"
  40. test list-1.19 {basic tests} {list a\v \{\v} "{a\v} \\\{\\v"
  41. test list-1.20 {basic tests} {list \"\}\{} "\\\"\\}\\{"
  42.  
  43. # For the next round of tests create a list and then pick it apart
  44. # with "index" to make sure that we get back exactly what went in.
  45.  
  46. set num 1
  47. proc lcheck {a b c} {
  48.     global num d
  49.     set d [list $a $b $c]
  50.     test list-2.$num {what goes in must come out} {lindex $d 0} $a
  51.     set num [expr $num+1]
  52.     test list-2.$num {what goes in must come out} {lindex $d 1} $b
  53.     set num [expr $num+1]
  54.     test list-2.$num {what goes in must come out} {lindex $d 2} $c
  55.     set num [expr $num+1]
  56. }
  57. lcheck a b c
  58. lcheck "a b" c\td e\nf
  59. lcheck {{a b}} {} {  }
  60. lcheck \$ \$ab ab\$
  61. lcheck \; \;ab ab\;
  62. lcheck \[ \[ab ab\[
  63. lcheck \\ \\ab ab\\
  64. lcheck {"} {"ab} {ab"}
  65. lcheck {a b} { ab} {ab }
  66. lcheck a{ a{b \{ab
  67. lcheck a} a}b }ab
  68. lcheck a\\} {a \}b} {a \{c}
  69.  
  70. test list-3.1 {error conditions} {catch list msg} 1
  71. test list-3.2 {error conditions} {
  72.     catch list msg
  73.     set msg
  74. } {wrong # args: should be "list arg ?arg ...?"}
  75.